const {User} = require('../models/models')

class UserController {
  async register(req, res, next) {
    const {email, number} = req.body

    // ПроверОчка
    const condidate = await User.findOne({where: {email}})
    if (condidate) {
       return res.status(404).json({message: "Пользователь с таким email уже существует"})
    }

    const user = await User.create({email, number})
    return res.json(user)
  }

  async getAllUsers(req, res, next) {
    try {
      const users = await User.findAll({})
      res.json(users)
    } catch (e) {
      return res.status(404).json({message: e.message})
    }
  }
}

module.exports = new UserController()
